package com.hais1992.oneday.activity;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSONObject;
import com.hais1992.oneday.R;
import com.hais1992.oneday.common.Config;
import com.hais1992.oneday.entity.User;
import com.hais1992.oneday.tools.GetHttpData;
import com.hais1992.oneday.tools.GetHttpData.GetCallback;

/**
 * 个人中心
 * @author Hello_海生
 * @date 2014年5月26日
 */
public class UserActivity extends Activity{
	private ImageView userImg; // 右邊的 個人中心
	private ImageView retuenImg; // 左邊的 返回按钮
	private TextView titleTv; // 标题栏
	private Button outLoginBt;	//退出登录
	private TextView nameTv;	//用户名
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.user_info);
		
		
		userImg = (ImageView) findViewById(R.id.rightImg);
		retuenImg = (ImageView) findViewById(R.id.leftImg);
		titleTv = (TextView) findViewById(R.id.titleTv);
		outLoginBt = (Button) findViewById(R.id.outLoginBt);
		nameTv = (TextView) findViewById(R.id.nameTv);
		
		
		Map<String, String> map = new HashMap<String, String>();
		map.put("email", Config.getCacheToken(UserActivity.this));
		map.put("key", Config.SERVER_KEY);
		new GetHttpData(Config.SERVER_URL+Config.GET_USER_URL, "POST", map, new GetCallback() {
			@Override
			public void onSuccess(String result) {
				JSONObject jsonObject = JSONObject.parseObject(result);
				User user = jsonObject.getObject("user", User.class);
				nameTv.setText(user.getName());
			}
		});
		
		
		
		outLoginBt.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Config.cacheToken(UserActivity.this, null);
				Toast.makeText(UserActivity.this, "注销成功！", Toast.LENGTH_SHORT).show();
				UserActivity.this.finish();
			}
		});
		
		
		
		titleTv.setText("OneDay");			//设置标题
		userImg.setVisibility(View.INVISIBLE);	// 設置 隐藏 個人中心 菜單
		
		// 设置返回键按钮
		retuenImg.setImageDrawable(getResources().getDrawable(R.drawable.left));
		retuenImg.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				UserActivity.this.finish();
			}
		});
		
	}
}
